package com.kk.wish.activity;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.kk.wish.R;

public class MainActivity extends Activity {

	private long exitTime = 0;
	private ActionBar actionBar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		actionBar = getActionBar();
		actionBar.show();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuItem add = menu.add(0, 1, 0, "Save");
		MenuItem open = menu.add(0, 2, 1, "Open");
		MenuItem close = menu.add(0, 3, 2, "Close");
		add.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
		open.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
		close.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
		return true; 
	}

	@Override
	public void onBackPressed() {
		if ((System.currentTimeMillis() - exitTime) > 2000) {
			Toast.makeText(getApplicationContext(), R.string.exit_tip, Toast.LENGTH_SHORT).show();
			exitTime = System.currentTimeMillis();
		} else {
			finish();
			System.exit(0);
		}
	}

}
